package com.ferrlo.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ferrlo.model.Project;
import com.ferrlo.service.IProjectManager;
import com.ferrlo.service.impl.UserManager;

@Controller
public class AdminProjectController {
	
	@Resource(name="projectManager")
	private IProjectManager projectManager;
	
	@RequestMapping(value="/adminProjDelete")
	public String deleteProject(HttpServletRequest request){
		
		String pid = request.getParameter("pid");
		Project project = findProjByPid(pid);
		
		projectManager.remove(project);
		
		return "index";
	}
	
	
	@RequestMapping(value="/adminProjModify")
	public String addProj(HttpServletRequest request){
		
		String pid = request.getParameter("pid");
		Project project = findProjByPid(pid);

		
		return "index";
	}
	
	
	
	private Project findProjByPid(String pid){
		String dqQuery = "";
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("",pid);

		List<Project> projects = projectManager.findListByDynamicQuery(dqQuery,map);
		if (projects.size() != 0) {
			return projects.get(0);
		}
		return null;
	}
	

}
